package bookmanagementsystem.gui;

import bookmanagementsystem.model.Book;
import javax.swing.*;
import java.awt.*;
import java.util.List;

public class BookQueryResultFrame extends JFrame {
    private JTextArea resultTextArea;

    // 构造方法用于展示单本图书信息
    public BookQueryResultFrame(Book book) {
        setTitle("图书查询结果");
        setSize(400, 300);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setLocationRelativeTo(null);

        initComponents();
        populateResultTextArea(book);
        addComponentsToFrame();
    }



    private void initComponents() {
        resultTextArea = new JTextArea();
        resultTextArea.setEditable(false);
    }

    private void populateResultTextArea(Book book) {
        if (book!= null) {
            StringBuilder message = new StringBuilder();
            message.append("图书ID：").append(book.getBookID()).append("\n")
                    .append("图书名称：").append(book.getBookName()).append("\n")
                    .append("作者：").append(book.getAuthorName()).append("\n")
                    .append("入库时间：").append(book.getEntryTime()).append("\n")
                    .append("库存数量：").append(book.getQuantityInLibrary()).append("\n")
                    .append("存放位置：").append(book.getLocation()).append("\n");
            resultTextArea.setText(message.toString());
        }
    }



    private void addComponentsToFrame() {
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(new JLabel("查询结果如下："), BorderLayout.NORTH);
        panel.add(new JScrollPane(resultTextArea), BorderLayout.CENTER);
        getContentPane().add(panel);
    }
}